package com.zqxq.lottery.cms.controller;

import com.zqxq.common.constant.Result;
import com.zqxq.common.utils.DateUtils;
import com.zqxq.common.utils.StrUtils;
import com.zqxq.lottery.cms.feign.LotteryServerFeignClient;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 苦智
 * @date 2018/10/8 14:56
 * @description 数据统计
 * @ClassName SysDataStatistics
 */
@Slf4j
@RestController
@RequestMapping("/data")
@Api(value = "数据统计",tags = "数据统计")
public class SysDataStatistics {
    @Autowired
    private LotteryServerFeignClient lotteryServerFeignClient;

    @ApiOperation(value = "日运营统计")
    @PostMapping("/dayStatistics")
    public Result dayStatistics(@ApiParam(value = "开始时间",required = false) String startTime,
                                @ApiParam(value = "结束时间",required = false) String endTime){
        log.info("数据统计 startTime={},endTime={}",startTime,endTime);
        return lotteryServerFeignClient.dayStatistics(startTime,endTime);
    }

    @ApiOperation("资金统计")
    @PostMapping("/profitCount")
    public Result dataProfitCount(@ApiParam(value = "开始时间",required = false) String startTime,
                                  @ApiParam(value = "日期类型1:月 2：日",required = false) @RequestParam(defaultValue = "2") Integer timeType,
                                  @ApiParam(value = "结束时间",required = false) String endTime){
        log.info("数据统计 startTime={},endTime={}",startTime,endTime);
        return lotteryServerFeignClient.getDataProfitCount(startTime,endTime,timeType);
    }

    @PostMapping("/getAllChannel")
    @ApiOperation(value = "获取所有的渠道")
    public Result getAllChannel(){
        return lotteryServerFeignClient.getAllChannel();
    }

    @ApiOperation("渠道统计")
    @PostMapping("/channelCount")
    public Result channelCount(@ApiParam(value = "页码",required = true) @RequestParam(defaultValue = "1") String pageNo,
                               @ApiParam(value = "每页大小",required = true) @RequestParam(defaultValue = "10") String pageSize,
                               @ApiParam(value = "开始时间",required = false) String startTime,
                               @ApiParam(value = "结束时间",required = false) String endTime,
                               @ApiParam(value = "平台",required = false) String source,
                               @ApiParam(value = "渠道",required = false) String channel){
        log.info("渠道统计 pageNo={},pageSize={},startTime={},endTime={},source={},channel={}",pageNo,pageSize,startTime,endTime,source,channel);
//        if (StrUtils.isEmpty(startTime) || StrUtils.isEmpty(endTime)){
//            //初始查询化时间
//            endTime = DateUtils.getCurrentDateStr();
//            startTime = DateUtils.dateToStr(DateUtils.addDays(new Date(),-30),"yyyy-MM-dd");
//        }
        Map<String,Object> paramMap = new HashMap<>();
        paramMap.put("pageNo",pageNo);
        paramMap.put("pageSize",pageSize);
        paramMap.put("startTime",startTime);
        paramMap.put("endTime",endTime);
        paramMap.put("source",source);
        paramMap.put("channel",channel);
        return lotteryServerFeignClient.getChannelCount(paramMap);
    }

    @ApiOperation("销售漏斗")
    @PostMapping("/saleFunnel")
    public Result saleFunnelCount(@ApiParam(value = "开始时间",required = false) String startTime,
                                 @ApiParam(value = "结束时间",required = false) String endTime,
                                 @ApiParam(value = "日期类型1:月 2：日",required = false) @RequestParam(defaultValue = "2") Integer timeType,
                                 @ApiParam(value = "客户端1:andriod 2：ios",required = false) Integer client,
                                 @ApiParam(value = "页码",required = true) @RequestParam(defaultValue = "1") Integer pageNo,
                                 @ApiParam(value = "每页大小",required = true) @RequestParam(defaultValue = "10") Integer pageSize){
        log.info("销售漏斗 startTime={},endTime={}",startTime,endTime);
        return lotteryServerFeignClient.saleFunnel(startTime,endTime,timeType,client,pageNo,pageSize);
    }

    @ApiOperation("用户活跃度分析")
    @PostMapping("/userActivity")
    public Result userActivityAnalysis(@ApiParam(value = "开始时间",required = false) String startTime,
                                       @ApiParam(value = "结束时间",required = false) String endTime,
                                       @ApiParam(value = "客户端1:andriod 2：ios",required = false) Integer source,
                                       @ApiParam(value = "页码",required = true) @RequestParam(defaultValue = "1") Integer pageNo,
                                       @ApiParam(value = "每页大小",required = true) @RequestParam(defaultValue = "10") Integer pageSize,
                                       @ApiParam(value = "日期类型1:月 2：日",required = false) @RequestParam(defaultValue = "2") Integer timeType){
        return lotteryServerFeignClient.userActivityAnalysis(startTime,endTime,source,pageNo,pageSize,timeType);
    }

    @ApiOperation("产品表现统计")
    @PostMapping("/productPerformance")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime", value = "开始时间", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "gameType",value = "游戏类型 0:全部 21:竞猜足球 1:LOL 2:DOTA2 3:CSGO 4:守望先锋 5:篮球 6:足球 7:王者荣耀 24:竞猜篮球",required = false,dataType = "Integer",paramType = "query"),
    })
    public Result productPerformance(String startTime,String endTime,Integer gameType){
        return lotteryServerFeignClient.productPerformance(startTime,endTime,gameType);
    }
}
